#ifndef xpack_lang_cxx_trim_end
#define xpack_lang_cxx_trim_end
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::lang_cxx::inc
#include"define/base_type.hpp"
#include"lang/cxx/index_of_last_miss.hpp"
#include"lang/cxx.hpp"
#include"macro/xforward.hpp"
#pragma pop_macro("xuser")

namespace mixc::lang_cxx{
    inline auto trim_end_core(auto self, auto const & pattern, auto const & compare) {
        if (auto index = self.index_of_last_miss(pattern, compare); index != not_exist){
            self->length    = index + 1;
            return self;
        }
        else{
            return decltype(self){};
        }
    }

    template<class item_t>
    template<class item_seq_t, class> 
    inline cxx<item_t> cxx<item_t>::trim_end(item_seq_t const & pattern, invoke_compare_t compare) const {
        auto list = inc::unified_seq<item_seq_t>(pattern);
        return trim_end_core(xthe, list, compare);
    }

    template<class item_t>
    template<class seq_t, class, class>
    inline cxx<item_t> cxx<item_t>::trim_end(seq_t && pattern, invoke_compare_t compare) const {
        auto list = inc::unified_seq<seq_t>(xforward(pattern));
        return trim_end_core(xthe, list, compare);
    }

    template<class item_t>
    inline cxx<item_t> cxx<item_t>::trim_end(item_cref_t pattern, invoke_compare_t compare) const {
        return xthe.trim_end({ pattern }, compare);
    }

    template<class item_t>
    inline cxx<item_t> cxx<item_t>::trim_end(the_cref_t pattern, invoke_compare_t compare) const {
        return xthe.trim_end({ pattern }, compare);
    }
}

#endif
